<?php

namespace App\Models\Activity;

use App\Models\BaseModel;
use App\Models\Kms\User\KmsUser;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ShopOrderActivityModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = 'shop_order_activity';

    protected $fillable = [
        "status",
        "updatedByUid",
        "updatedAt",
    ];

    const TYPE_1    = 1;
    const TYPE_TEXT = [
        self::TYPE_1 => "品牌活动"
    ];

    const SHOP_TYPE_ALL  = 0;
    const SHOP_TYPE_PART = 1;
    const SHOP_TYPE_TEXT = [
        self::SHOP_TYPE_ALL  => "全部门店",
        self::SHOP_TYPE_PART => "部分门店",
    ];

    const EXPIRE_TYPE_0    = 0;
    const EXPIRE_TYPE_1    = 1;
    const EXPIRE_TYPE_TEXT = [
        self::EXPIRE_TYPE_0 => "长期有效",
        self::EXPIRE_TYPE_1 => "限时有效",
    ];

    const STATUS_0    = 0;
    const STATUS_1    = 1;
    const STATUS_2    = 2;
    const STATUS_3    = 3;
    const STATUS_TEXT = [
        self::STATUS_0 => "待发布",
        self::STATUS_1 => "正常",
        self::STATUS_2 => "暂停",
        self::STATUS_3 => "已结束",
    ];

    const BUSINESS_TYPE_0    = 0;
    const BUSINESS_TYPE_1    = 1;
    const BUSINESS_TYPE_2    = 2;
    const BUSINESS_TYPE_3    = 3;
    const BUSINESS_TYPE_4    = 4;
    const BUSINESS_TYPE_TEXT = [
        self::BUSINESS_TYPE_0 => "适用门店",
        self::BUSINESS_TYPE_1 => "已报名门店",
        self::BUSINESS_TYPE_2 => "未报名门店",
        self::BUSINESS_TYPE_3 => "已传活动照片门店",
        self::BUSINESS_TYPE_4 => "未传活动照片门店",
    ];

    /**
     * @return HasMany
     */
    public function shopRel(): HasMany
    {
        return $this->hasMany(ShopOrderActivityShopRelModel::class, "shopOrderActivityId", "id");
    }

    /**
     * @return HasMany
     */
    public function shopJoinRel(): HasMany
    {
        return $this->hasMany(ShopOrderActivityShopJoinRelModel::class, "shopOrderActivityId", "id")
                    ->where("status", ShopOrderActivityShopJoinRelModel::STATUS_APPLY_IN);
    }

    /**
     * @return HasMany
     */
    public function shopFeedbackRel(): HasMany
    {
        return $this->hasMany(ShopOrderActivityFeedbackModel::class, "activityId", "id");
    }


    /**
     * @return HasOne
     */
    public function createdUserRel(): HasOne
    {
        return $this->hasOne(KmsUser::class, "rmsUserId", "createdByUid");
    }
}
